package org.example.test.service;

import org.example.test.MovieTypeEnum;
import org.example.test.Rental;

import java.math.BigDecimal;

public class DefaultCalculate{

    public static BigDecimal calculatePrice(Rental obj) {
        BigDecimal price = new BigDecimal(obj.getMovie().getPrice());
        // 没有优惠天数时（新片用）
        if(obj.getMovie().getMinDiscountDays() ==null ){
            return price.multiply(new BigDecimal(obj.getDayRented()));
        }
        // 有优惠时的计算
        if (obj.getDayRented() > obj.getMovie().getMinDiscountDays()) {
            BigDecimal bigDecimal = new BigDecimal(String.valueOf(obj.getDayRented() - obj.getMovie().getMinDiscountDays()));
            price = price.add(bigDecimal.multiply(new BigDecimal(obj.getMovie().getDiscountPrice())));
        }
        return price;
    }

    public static Integer calculateRenterPoints(Rental obj) {
        int frequentRenterPoints = 1;
        //add bonus for a two day new release rental
        if (MovieTypeEnum.NEW_RELEASE.getPriceCode().equals(obj.getMovie().getPriceCode()) && obj.getDayRented() > 1) {
            frequentRenterPoints++;
        }
        return frequentRenterPoints;
    }
}
